
<style>

.alert{padding-left: 0;margin-left:0;margin-top:8px;}
.voilet {padding-left: 0;margin-left:0;}
.form-group .checkbox-inline{margin-left:8px;}
#checkAll{margin-left:8px;}
</style>
<pre>请选择需要执行命令的主机</pre>

<div class="voilet">
    <form method="POST" id="reasonform"  class="navbar-form navbar-left" role="search" onsubmit="return false" >{% csrf_token %}
        <div class="voilet_test">
            {% for i in service_name %}
                <button type="button" id="server_node{{ i.id }}" style="cursor:pointer" class="btn btn-sm btn-info">{{ i }}</button>
            {% endfor %}
        </div>
        <div class="alert alert-dismissable alert-info">
            <div id="node_name">　亲！点击项目名称选择主机哦</div>
        </div>
{#    {{ user.department }}#}
        {% if user.department == "op" %}
        <div class="row">
          <div class="col-lg-6">
            <div class="input-group">
              <div class="input-group-btn">
                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">Action <span class="caret"></span></button>
                <ul class="dropdown-menu">
                  <li><a href="#">state.running</a></li>
                  <li><a href="#">state.show_highstate</a></li>
                  <li class="divider"></li>
                  <li><a href="#">garins</a></li>
                  <li><a href="#">ping</a></li>
                  <li class="divider"></li>
                  <li><a href="#">test.ping</a></li>
                  <li><a href="#">version</a></li>
                  <li><a href="#">echo</a></li>
                </ul>
              </div><!-- /btn-group -->
              <input type="text" class="form-control" name="salt_node_name" id = "salt_node_name" placeholder="输入主机名"  maxlength="100" size="100" />
              <span class="input-group-addon ">命令类型
                  <select id="id_brand"  name="comm_shell">
                    <option value="cmd" selected="selected">cmd.run</option>
                    <option value="grains">grains.item</option>
                    <option value="ping">test.ping</option>
                   </select>
              </span>
            </div><!-- /input-group -->
          </div><!-- /.col-lg-6 -->
          <div class="col-lg-6">
            <div class="input-group">
             <span class="input-group-btn">
                <button class="btn btn-default disabled" type="button">命令</button>
              </span>
             <input type="text" class="form-control" name="salt_cmd" id="salt_cmd" placeholder="如:ifconfig" maxlength="100" size="100"/>
              <span class="input-group-btn">
                <button class="btn btn-success" id="button" type="button">执行</button>
              </span>
{#                <button type="submit" id="button" class="btn btn-default" id="but_salt_state_sls">安装</button>#}
            </div><!-- /input-group -->
          </div><!-- /.col-lg-6 -->
        </div><!-- /.row -->
        {% else %}
        <div class="row">
          <div class="col-lg-6">
            <div class="input-group">
              <div class="input-group-btn">
                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">Action <span class="caret"></span></button>
                <ul class="dropdown-menu">
                  <li><a href="#">state.running</a></li>
                  <li><a href="#">state.show_highstate</a></li>
                  <li class="divider"></li>
                  <li><a href="#">garins</a></li>
                  <li><a href="#">ping</a></li>
                  <li class="divider"></li>
                  <li><a href="#">test.ping</a></li>
                  <li><a href="#">version</a></li>
                  <li><a href="#">echo</a></li>
                </ul>
              </div><!-- /btn-group -->
              <input type="text" class="form-control" name="salt_node_name" id = "salt_node_name" placeholder="输入主机名"  maxlength="100" size="100" />
              <span class="input-group-addon ">命令类型
                  <select id="id_brand"  name="comm_shell">
                    <option value="cmd" selected="selected">cmd.run</option>
                    <option value="grains">grains.item</option>
                    <option value="ping">test.ping</option>
                   </select>
              </span>
            </div><!-- /input-group -->
          </div><!-- /.col-lg-6 -->
          <div class="col-lg-6">
            <div class="input-group">
             <span class="input-group-btn">
                <button class="btn btn-default disabled" type="button">命令</button>
              </span>
             <input type="text" class="form-control" name="salt_cmd" id="salt_cmd" placeholder="如:ifconfig" maxlength="100" size="100"/>
              <span class="input-group-btn">
                <button class="btn btn-success" id="button" type="button">执行</button>
              </span>
{#                <button type="submit" id="button" class="btn btn-default" id="but_salt_state_sls">安装</button>#}
            </div><!-- /input-group -->
          </div><!-- /.col-lg-6 -->
        {% endif %}
    </form>

</div>

<script type="text/javascript">
$(document).ready(function(){
  $('#button').click(function(){
    jQuery.ajax({
      url: "/salt/cmd/",                  // 提交的页面
      data: $('#reasonform').serialize(), // 从表单中获取数据
      type: "POST",                       // 设置请求类型为"POST"，默认为"GET"
      beforeSend: function(){             // 设置表单提交前方法
        //alert('表单提交前');
      },
      error: function(request){           // 设置表单提交出错
        alert("表单提交出错，请稍候再试");
      },
      dataType:'text',
      success: function(msg){
          $("#salt_cmd_run").html(msg)
{#        alert(msg);                       // 设置表单提交完成使用方法#}
      }
    });
    return false;
  });
});

//根据人员查询业务分类和主机
{% for i in service_name %}
$(document).ready(function(){
  $("#server_node{{ i.id }}").click(function(){
        $.ajax({
       type: "GET",
       url: "/salt/type/{{ i.id }}/"})  .done(function( data ) {
        $("#node_name").html(data);
      });
  });
});
{% endfor %}


</script>


<div id="salt_cmd_run"></div>



